<?php if (!defined("_ECRIRE_INC_VERSION")) return;
/**
 * Aloha Cart
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage alohacart
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/AlohaCart
 */

include_spip('functions/pdk_common');
include_spip('functions/pdk_database');

function formulaires_alohacart_order_charger_dist($id_order){
	$valeurs = array();
    
    $order_mdl = pdk_load_class('AlohacartOrderModel','classes');
    $currency_mdl = pdk_load_class('CurrencyModel','classes');
    
    $valeurs = $order_mdl->select_by_id($id_order, true);
    
    $valeurs['statuts'] = select_reference_to_array('spip_alohacart_orders_statuts', 'id_statut', 'titre', null, array(), array(), 'id_statut');
    foreach ($valeurs['statuts'] as $key=>$titre) {$valeurs['statuts'][$key] = supprimer_numero($titre); }
    
    $currency = $currency_mdl->select_by_id($valeurs['id_currency']);
    $valeurs['currency_titre'] = extraire_multi($currency['titre']);
    
    // Calculate total price, shown for user according to order currency's rate
    $sign_pre = $currency['sign_pre']?extraire_multi($currency['sign_pre']).' ':'';
    $sign_after = $currency['sign_after']?' '.extraire_multi($currency['sign_after']):'';
    $valeurs['total_price_user'] = $sign_pre.($valeurs['total_price']*$valeurs['currency_rate']).$sign_after;
    
    $valeurs['shipping_titre'] = extraire_multi($valeurs['shipping_titre']);
    $valeurs['payment_titre'] = extraire_multi($valeurs['payment_titre']);
    
    $valeurs['invoice_action_link'] = 'alohacart_payment_invoice';
    
    // Make order viewed
    if (!$valeurs['viewed'])
        $order_mdl->update_by_id($id_order, array('viewed'=>1));
    
	return $valeurs;
}
